<?php
class StepSubMenu extends CWidget {
	public $items = array ();

	public $model = null;

	public function run() {
		$av_items = array (
			'create' => CHtml::link(Yii::t('submenu', 'New step'), array (
				'create'
			)),
			'admin' => CHtml::link(Yii::t('submenu', 'Manage steps'), array (
				'admin'
			))
		);

		if ($this->model != null) {
			$av_items['update'] = CHtml::link(Yii::t('submenu', 'Update step'), array (
				'update',
				'id' => $this->model->mnemonic
			));

			if ($this->model->mnemonic != Constants::ADMIN_USER && $this->model->mnemonic != Constants::ROOT_USER) {
				$av_items['delete'] = CHtml::linkButton(Yii::t('submenu', 'Delete step'), array (
					'submit' => array (
						'delete',
						'id' => $this->model->mnemonic
					),
					'confirm' => Yii::t('submenu', 'Are you sure?')
				));
			}
		}

		$items = array ();
		$controller = $this->controller;
		$action = $controller->action;
		foreach ($this->items as $item) {
			if (array_key_exists($item, $av_items)) {
				$items[] = $av_items[$item];
			}
		}
		$this->render('subMenu', array (
			'items' => $items
		));
	}
}
?>
